# Maintainer: Sven-Hendrik Haase <svenstaro@archlinux.org>
# Contributor: Wesley Moore <wes@wezm.net>
pkgname=sd
pkgver=0.7.6
pkgrel=2
pkgdesc='Intuitive find & replace'
arch=('loong64' 'x86_64')
url="https://github.com/chmln/sd"
license=('MIT')
depends=('gcc-libs')
makedepends=('rust')
source=("$pkgname-$pkgver.tar.gz::https://github.com/chmln/sd/archive/v${pkgver}.tar.gz")
sha256sums=('faf33a97797b95097c08ebb7c2451ac9835907254d89863b10ab5e0813b5fe5f')

build() {
  cd "$pkgname-$pkgver"

  cargo build --release --locked
}

check() {
  cd "$pkgname-$pkgver"
  cargo test --release --locked
}

package() {
  install -Dm755 "$pkgname-$pkgver/target/release/$pkgname" "$pkgdir/usr/bin/$pkgname"
  install -Dm644 "$pkgname-$pkgver/LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  cd $pkgname-$pkgver/target/release/build

  # Find and package the man page (because cargo --out-dir is too new)
  find . -name sd.1 -type f -exec install -Dm644 {} "$pkgdir/usr/share/man/man1/sd.1" \;

  # Find and package the bash completion file
  find . -name sd.bash -type f -exec install -Dm644 {} "$pkgdir/usr/share/bash-completion/completions/sd" \;

  # Find and package the zsh completion file (not in zsh-completions yet)
  find . -name _sd -type f -exec install -Dm644 {} "$pkgdir/usr/share/zsh/site-functions/_sd" \;

  # Find and package the fish completion file
  find . -name sd.fish -type f -exec install -Dm644 {} "$pkgdir/usr/share/fish/vendor_completions.d/sd.fish" \;
}
